import matplotlib.pyplot as plt
import pandas as pd

# x = [1,2,3,4,5,6]
# y = [19,24,37,43,55,68]
#
# plt.scatter(x,y)
# plt.show()

aa = r'./data/JDdata.xls'
bb = r'./data/JDcar.xls'
dfaa = pd.DataFrame(pd.read_excel(aa))
dfbb = pd.DataFrame(pd.read_excel(bb))

df1 = dfaa[['业务日期','金额']]
df2 = dfbb[['投放日期','支出']]

# 去除空日期和金额为0的交易记录
df1 = df1[df1['业务日期'].notnull() & df1['金额'] != 0]
df2 = df2[df2['投放日期'].notnull() & df2['支出'] != 0]

df1['业务日期'] = pd.to_datetime(df1['业务日期'])
df2['投放日期'] = pd.to_datetime(df2['投放日期'])

dfData = df1.set_index('业务日期',drop=True)
dfCar = df2.set_index('投放日期',drop=True)

# 按月度统计并显示销售额
dfData_month = dfData.resample('M').sum().to_period('M')
# 按月度统计并显示广告费支出
dfCar_month = dfCar.resample('M').sum().to_period('M')

# x为广告费 ， y销售收入
x= pd.DataFrame(dfCar_month['支出'])
y= pd.DataFrame(dfData_month['金额'])

# 中文乱码
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.sans-serif'] = ['Heiti TC']

plt.title('销售收入与广告费散点图')
plt.scatter(x,y,color='red')
plt.show()








